add_rules("mode.debug", "mode.release")

local workdir = os.scriptdir()
-- add_syslinks("pthread")

-- add_repositories("local-repo quickjs-2023-12-09/build") -- 需要符合 repo/packages/c/coroutine xmake-repo 的包格式
add_repositories("local-repo quickjs-2024-01-13/build") -- 需要符合 repo/packages/c/coroutine xmake-repo 的包格式
add_requires("qjs", { debug = true })



target("jsco")
    set_kind("binary")
    add_files("src/jsco.cpp")
    if is_plat("macosx") then
        add_frameworks("JavaScriptCore", "Foundation", "CoreFoundation")
    end

target("jsco_exception")
    set_kind("binary")
    add_files("src/jsc_exception.cc")
    if is_plat("macosx") then
        add_frameworks("JavaScriptCore", "Foundation", "CoreFoundation")
    end
target("jsco-qjs")
    set_kind("binary")
    add_files("src/jsco-qjs.cpp")
    add_includedirs("quickjs-2024-01-13/")
    add_packages("qjs")
    local qjs_rpath = workdir .. "quickjs-2024-01-13/build/packages/q/qjs/macosx/x86_64/debug/lib"
    add_rpathdirs(qjs_rpath)

target("jsco-qjs-auto")
    set_kind("binary")
    add_files("src/jsco-qjs-auto.cpp")
    add_includedirs("quickjs-2024-01-13/")
    add_packages("qjs")


target("jsco-promise")
    set_kind("binary")
    add_files("src/qjs_promise.cpp")
    add_includedirs("quickjs-2024-01-13/")
    add_packages("qjs")
    local qjs_rpath = workdir .. "quickjs-2024-01-13/build/packages/q/qjs/macosx/x86_64/debug/lib"
    add_rpathdirs(qjs_rpath)

target("jsc_promise")
    set_kind("binary")
    add_files("src/jsc_promise.cpp")
    if is_plat("macosx") then
        add_frameworks("JavaScriptCore", "Foundation", "CoreFoundation")
    end

target("gsf")
    set_kind("binary")
    add_files("src/jsco-global-static-function.cpp")
    if is_plat("macosx") then
        add_frameworks("JavaScriptCore", "Foundation", "CoreFoundation")
    end

target("sf")
    set_kind("binary")
    add_files("src/static_function.cpp")
    if is_plat("macosx") then
        add_frameworks("JavaScriptCore", "Foundation", "CoreFoundation")
    end

target("qjs_async")
    set_kind("binary")
    add_files("src/qjs_async.cpp")
    add_includedirs("quickjs-2024-01-13/")
    add_packages("qjs")
    local qjs_rpath = workdir .. "quickjs-2024-01-13/build/packages/q/qjs/macosx/x86_64/debug/lib"
    print('workdir: ' .. workdir)
    add_rpathdirs(qjs_rpath)